package cn.xuyang520.tyim.sys.controller;

import cn.xuyang520.tyim.sys.domain.TySysUser;
import cn.xuyang520.tyim.sys.domain.TySysUserRepository;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by admin on 2017/3/31.
 */
@Controller
@RequestMapping("/tyUserController")
public class TySysUserController extends TySysBaseController {
    @Autowired
    private TySysUserRepository tySysUserRepository;

    @RequestMapping
    @RequiresPermissions("sys:user:index")
    public String index() {
        return "page/sys/userList";
    }


    @RequestMapping("/findAll")
    @ResponseBody
    @RequiresPermissions("sys:user:index")
    public Object findAll() {

        Subject subject = SecurityUtils.getSubject();
        System.out.println(subject.isPermitted("sys:user:findAll"));

        List<TySysUser> all = tySysUserRepository.findAll();

        //all.addAll(all);
        //all.addAll(all);
        //all.addAll(all);
        //all.addAll(all);
        //all.addAll(all);
        return all;
    }

    public Object save(TySysUser user) {
        tySysUserRepository.save(user);
        return success();
    }



}
